//
//  StudyUnitCell.swift
//  BLH
//
//  Created by zhangshumeng on 2021/8/12.
//

import UIKit

class StudyUnitCell: UITableViewCell {

    lazy var iconView: UIImageView = {
        let view = UIImageView()
        view.contentMode = .scaleAspectFit
        return view
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = .none
        addSubviews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func addSubviews() {
        
        contentView.addSubview(iconView)
        
        iconView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
            make.bottom.equalToSuperview()
        }
    }

    func updateLayout(_ index: Int) {
        let i = index % 4
        switch i {
        case 0:
            iconView.snp.updateConstraints { make in
                make.centerX.equalToSuperview().offset(20)
            }
        case 1:
            iconView.snp.updateConstraints { make in
                make.centerX.equalToSuperview().offset(-60)
            }
        case 2:
            iconView.snp.updateConstraints { make in
                make.centerX.equalToSuperview().offset(-20)
            }
        case 3:
            iconView.snp.updateConstraints { make in
                make.centerX.equalToSuperview().offset(60)
            }
        default:
            break
        }
    }
}
